import groovy.xml.StreamingMarkupBuilder

def builder = new StreamingMarkupBuilder()

def date1 = Date.parse('yyyy-MM-dd', '2015-01-01')
def date2 = Date.parse('yyyy-MM-dd', '2015-02-02')

// 用 bind 方法引入 markup 闭包
def writable = builder.bind {
	// 根节点放在 markup 闭包内, 其他就一样了
	invoices {
		invoice(date: date1) {
			item(count: 5) {
				product(name: 'ULC', doller: 1499)
			}
			item(count: 1) {
				product(name: 'Visual Editor', doller: 499)
			}
		}
		invoice(date: date2) {
			item(count: 4) {
				product(name: 'Visual Editor', doller: 499)
			}
		}
	}
}

println writable.toString()
